package com.sunagy.demand.front.controller;

import com.sunagy.demand.front.VO.ResultVO;
import com.sunagy.demand.front.dataobject.PickProduct;
import com.sunagy.demand.front.dto.CustomerProductDto;
import com.sunagy.demand.front.service.CustomerProductService;
import com.sunagy.demand.front.utils.ResultVOUtil;
import com.sunagy.demand.front.utils.UserContext;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * desc：用户需求进程接口
 * author：三餘無夢生
 * date：2018/4/11
 * time：下午4:10
 */
@Slf4j
@RestController
@RequestMapping("/customerProduct")
@Api(value = "客户端我的产品", description = "客户端我的产品模块")
public class CustomerProductController {

    @Autowired
    private CustomerProductService customerProductService;
//
    @ApiOperation(value = "查询我选择的产品", notes = "根据用户token信息查询用户自己选择的产品")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "java.lang.String", name = "Authorization", value = "token", required = false, paramType = "header")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "接口异常")
    })
    @RequestMapping(method = RequestMethod.GET)
    public ResultVO<List<CustomerProductDto>> getList() {
        List<CustomerProductDto> customerProductDtoList = customerProductService.getProductListByUserId(UserContext.getUserID());
        return ResultVOUtil.success(customerProductDtoList);
    }

    @ApiOperation(value = "选择产品", notes = "选择某个产品")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "java.lang.String", name = "Authorization", value = "token", required = false, paramType = "header"),
            @ApiImplicitParam(dataType = "java.lang.String", name = "id", value = "id", required = false, paramType = "path")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "接口异常")
    })
    @RequestMapping(value = "/{id}",method = RequestMethod.POST)
    public ResultVO<CustomerProductDto> pickProduct(@PathVariable("id") Integer productId) {
        CustomerProductDto customerProductDto = customerProductService.pickProduct(UserContext.getUserID(),productId);
        return ResultVOUtil.success(customerProductDto);
    }

    @ApiOperation(value = "批量选择产品", notes = "选择某些产品")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "java.lang.String", name = "Authorization", value = "token", required = false, paramType = "header"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "接口异常")
    })
    @RequestMapping(value = "",method = RequestMethod.POST)
    public ResultVO<List<CustomerProductDto>> pickMutiProduct(@RequestBody PickProduct pickProduct) {
        List<CustomerProductDto> customerProductDtoList = customerProductService.pickProducts(UserContext.getUserID(),pickProduct.getIds(),pickProduct.getProgressId());
        return ResultVOUtil.success(customerProductDtoList);
    }

}
